<?php
namespace app\api\controller;

use app\common\model\live\RoomModel;

class PublicController extends BaseController
{
  protected $model;

  /**
   * 初始化
   */
  public function __construct()
  {
    parent::__construct();
    $this->model = new RoomModel();
  }

  /**
   * 直播登录
   * type host 主持人 guests嘉宾 assistant助理
   * @throws \Exception
   */
  public function login(){
    $data = $this->request->param();
    $this->validate($data,[
        'room_id|房间号'=>'require',
        'nick|姓名'=>'require',
        'password|密码'=>'require',
    ]);
    $user = $this->model->login($data['room_id'],$data['nick'],$data['password'],'guests');
    $this->result(['token'=>$this->model->setToken($user,time()+3600*24),'user'=>$user]);
  }

}